<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2021/5/12
  Time: 9:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <%
        //获取项目的根路径
        String path = request.getContextPath();
        String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>华子图书馆</title>
    <script src="<%=basePath%>/jquery-1.12.4.js" type="text/javascript"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/dcy/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>/sweetalert.css">
    <script type="text/javascript" src="<%=basePath%>/sweetalert-dev.js"></script>
</head>
<body>
            <%--分页/查询--%>
            <div>
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                    <legend>读者信息管理</legend>
                </fieldset>
                <form action="<%=basePath%>LibraryServlet?czm=sel" method="get">
                    姓 名:<input type="text" name="name">
                    <input type="submit" value="查询">
                </form>
                <table  cellspacing="4"  class="layui-table" lay-even="" lay-skin="nob">
                    <colgroup>
                        <col width="150">
                        <col width="150">
                        <col width="200">
                        <col>
                    </colgroup>
                    <tr>
                        <th>卡号</th>
                        <th>身份证</th>
                        <th>密码</th>
                        <th>姓名</th>
                        <th>年龄</th>
                        <th>联系方式</th>
                        <th>余额</th>
                        <th>操作</th>
                    </tr>
                    <c:forEach items="${requestScope.page.list}" var="lib">
                        <tr>
                            <td>${lib.getReaId()}</td>
                            <td>${lib.getIdCard()}</td>
                            <td>${lib.getPwd()}</td>
                            <td>${lib.getName()}</td>
                            <td>${lib.getAge()}</td>
                            <td>${lib.getPhone()}</td>
                            <td>${lib.getPrice()}</td>
                            <td>
                                <a herf="<%=basePath%>LibraryServlet" onclick="cancels(${lib.getReaId()})">注销</a>
                                <a href="<%=basePath%>LibraryServlet?czm=cs&reaid=${lib.getReaId()}&idcard=${lib.getIdCard()}&pwd=${lib.getPwd()}&name=${lib.getName()}&age=${lib.getAge()}&phone=${lib.getPhone()}&price=${lib.getPrice()}">修改</a>
                                <a href="<%=basePath%>LibraryServlet?czm=chong&id=${lib.getReaId()}&">充值</a>
                            </td>
                        </tr>
                    </c:forEach>
                </table>
                <c:if test="${requestScope.page.currentPage>1}">
                    <a href="<%=basePath%>LibraryServlet?currentPage=${requestScope.page.currentPage-1}&czm=sel}">上一页</a>
                </c:if>
                ${requestScope.page.currentPage}/${requestScope.page.totalPage}
                <c:if test="${requestScope.page.currentPage < requestScope.page.totalPage}">
                    <a href="<%=basePath%>LibraryServlet?currentPage=${requestScope.page.currentPage+1}&czm=sel">下一页</a>
                </c:if>
</div>
<script type="text/javascript">

    //删除方法
    function cancels(id){
        let b= confirm("确定注销？");
        if(b){
            let Id=id;
            $.ajax({
                url:"LibraryServlet",
                type:"post",//请求方式, get或post
                data:{
                    workingID:Id,
                    czm:"cancel"
                },//请求参数
                dataType :"json",//数据格式，一般是json
                success:function(data) {// 回调函数, data就是请求返回结果
                    if (data){
                        swal("注销成功");
                        location.reload();
                    }
                }
            });
        }

    }
</script>
</body>
</html>
